/*---------------------------------------------------------*
*                Global Configuration Class                *
*                                                          *
*          Created By: Matthew Hoyes & Ronald Ram          *
*                                                          *
*      This class will hold all global data that will      *
*      be used by the entire project to track project      *
*      data and game states                                *
*                                                          *      
*----------------------------------------------------------*/

#region USING STATEMENTS

using System;
using System.Collections.Generic;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Audio;

using BrickBreaker.Core;
using Hud;

#endregion

namespace BrickBreaker
{
    #region ENUMS

    public enum MenuState { MAIN, NEW_GAME, CONTINUE, OPTIONS, HELP, EXIT };
    public enum SubMenuState { CLASSIC, TIMED, ENDLESS, PvP, PvC, MISC, RETURN }; /*more items...*/ 
    public enum ProgramState { MENU, PLAY, PAUSE, GAME_OVER, EXIT };
    public enum GameModes { CLASSIC, TIMED, ENDLESS, PvP, PvC, MISC, NONE };

    #endregion

    public class BBGlobalConfig
    {
        #region PROGRAM CREATION 
        //
            private static SpriteBatch spriteBatch;
            public static ContentManager content;
            public static GraphicsDeviceManager graphics;
            //
            public static int WindowWidth;
            public static int WindowHeight;

            #region Temporary
            //
                public static bool DisplayDebug;
            //
            #endregion
        //
        #endregion PROGRAM CREATION


        #region TRACK GLOBAL DATA, PROGRAM STATES
            //
            public static BBKeyboard keyboard;
            public static ProgramState programState;
            public static MenuState menuState;
            public static SubMenuState subMenuState;
            public static GameModes gameMode;
            //
            #region Temporary
            //
                public static BBBall greenDot;
                public static BBBall blueDot;
            //
            #endregion
        //
        #endregion TRACK GLOBAL DATA, PROGRAM STATES


        #region Asset Storage
            //
            #region Asset Folders
            //
                public static string BackgroundFolder = @"Backgrounds\";
                public static string BallsFolder = @"Balls\";
                public static string BricksFolder = @"Bricks\";
                public static string PaddlesFolder = @"Paddles\";
                public static string MiscFolder = @"Misc\";
                public static string FontsFolder = @"FontStyles\";
                public static string AudioFolder = @"Audio\";
                public static string PowerupsFolder = @"Powerups\";
            //
            #endregion
            //
            #region Textures
            //
                #region Backgrounds
                    //
                    //public static Texture2D background_yellow;
                    public static Texture2D background_title;
                    public static Texture2D background_menu;
                    public static Texture2D background_gamemode;
                    public static Texture2D background_help;
                    public static Texture2D background_pause;

                    public static Texture2D background_ice01;
                    public static Texture2D background_ice02;
                    public static Texture2D background_grid;                   
                    //
                #endregion
                //
                #region Debug
                //
                    public static Texture2D UncheckedBox;
                    public static Texture2D CheckedBox;
                //
                #endregion
                //
                #region Paddle
                //
                    public static Texture2D paddle_ball;
                    public static Texture2D paddle_short;
                    public static Texture2D paddle_normal;
                    public static Texture2D paddle_long;
                    public static Texture2D singleCannon;
                    public static Texture2D doubleCannons;

                    public static Texture2D bullet;
                    public static Texture2D paddle_track;
                //
                #endregion
                //
                #region Ball
                //
                    public static Texture2D bbball_black;
                    public static Texture2D bbball_blue;
                    public static Texture2D bbball_blurple;
                    public static Texture2D bbball_green;
                    public static Texture2D bbball_greenblue;
                    public static Texture2D bbball_purple;
                    public static Texture2D bbball_red;
                    public static Texture2D bbball_yellow;

                    public static Texture2D bbball_launchDirection;

                //
                #endregion
                //
                #region Brick
                //
                    //public static Texture2D brick_placeholder;
                    public static Texture2D brick_red;
                    public static Texture2D brick_red_cracked;
                    
                    public static Texture2D brick_blue;
                    public static Texture2D brick_blue_cracked;
                    public static Texture2D brick_blue_cracked2;
                    
                    public static Texture2D brick_green;
                    public static Texture2D brick_green_cracked;
                    public static Texture2D brick_green_cracked2;
                    public static Texture2D brick_green_cracked3;

                    public static Texture2D brick_orange;
                    public static Texture2D brick_orange_cracked;
                    public static Texture2D brick_orange_cracked2;
                    public static Texture2D brick_orange_cracked3;
                    
                    public static Texture2D brick_grey;
                    
                    
                    
                    
                //
                #endregion
                //
                #region Power Up
                //
                    public static Texture2D powerup_bomb;
                    public static Texture2D powerup_doubleshooter;
                    public static Texture2D powerup_fast;
                    public static Texture2D powerup_long;
                    public static Texture2D powerup_normal;
                    public static Texture2D powerup_shooter;
                    public static Texture2D powerup_short;
                    public static Texture2D powerup_slow;
                    public static Texture2D powerup_split;
                    public static Texture2D powerup_sticky;
                    public static Texture2D powerup_multiplierx2;
                    public static Texture2D powerup_multiplierx4;
                //
                #endregion
            //
            #endregion
            //
            #region Sound Effects

            public static SoundEffect BrickHitSound;
            public static SoundEffect BrickDestroyedSound;

            public static SoundEffect PaddleCollisionSound;
            public static SoundEffect WallCollisionSound;
            public static SoundEffect BackgroundMusic;
            public static SoundEffect DyingSound;
            public static SoundEffect BallLaunchSound;
            public static SoundEffect ShootingSound1;
            public static SoundEffect CollectPowerupSound;
            public static SoundEffect LevelWonSound;
            #endregion
            //
            #region Fonts
            //
                public static SpriteFont font;
                public static SpriteFont fontSelected;
            //
            #endregion
        //
        #endregion

        public static BBPowerupManager powerupManager;

        public static BBHud hud;

        //Constructor not accessible - using Singleton Design Pattern
        private BBGlobalConfig() { /* PRIVATE CONSTRUCTOR */ }

        /// <summary>
        /// Retrieves the width of the screen.
        /// </summary>
        public static int getWindowWidth() { return graphics.PreferredBackBufferWidth; }

        /// <summary>
        /// Retrieves the height of the screen.
        /// </summary>
        public static int getWindowHeight() { return graphics.PreferredBackBufferHeight; }

        /// <summary>
        /// Retrieves the spritebatch
        /// </summary>
        public static SpriteBatch getSpriteBatch() { return spriteBatch; }

        /// <summary>
        /// Creates a spritebatch to handle all graphics
        /// </summary>
        /// <param name="graphicsDevice">The graphics device which handles al graphics.</param>
        public static void createSpriteBatch(GraphicsDevice graphicsDevice)
        {
            spriteBatch = new SpriteBatch(graphicsDevice);
        }

        /// <summary>
        /// Loads all the global content.
        /// </summary>
        public static void LoadContent()
        {
        //
            #region Load Texture Assets
            //
                #region BACKGROUND_and_MENU
                //
                    //background_yellow = content.Load<Texture2D>(BackgroundFolder + "background_yellow");

                    background_title = content.Load<Texture2D>(BackgroundFolder + "background_title");
                    background_menu = content.Load<Texture2D>(BackgroundFolder + "background_menu");
                    background_gamemode = content.Load<Texture2D>(BackgroundFolder + "background_gamemode");
                    background_help = content.Load<Texture2D>(BackgroundFolder + "background_help");
                    background_pause = content.Load<Texture2D>(BackgroundFolder + "background_pause");
                    
                    background_ice01 = content.Load<Texture2D>(BackgroundFolder + "background_ice01");
                    background_ice02 = content.Load<Texture2D>(BackgroundFolder + "background_ice02");
                    background_grid = content.Load<Texture2D>(BackgroundFolder + "background_grid");
                //
                #endregion
                //
                #region MENU_CONTRLS
                //
                    UncheckedBox = content.Load<Texture2D>(MiscFolder + "UncheckedBox");
                    CheckedBox = content.Load<Texture2D>(MiscFolder + "CheckedBox");
                //
                #endregion
                //
                #region PADDLE
                //
                    paddle_ball = content.Load<Texture2D>(PaddlesFolder + "paddle_ball");
                    paddle_short = content.Load<Texture2D>(PaddlesFolder + "paddle_short");
                    paddle_normal = content.Load<Texture2D>(PaddlesFolder + "paddle_normal");
                    paddle_long = content.Load<Texture2D>(PaddlesFolder + "paddle_long");

                    singleCannon = content.Load<Texture2D>(PaddlesFolder + "paddle_singleCannon");
                    doubleCannons = content.Load<Texture2D>(PaddlesFolder + "paddle_doubleCannons");

                    paddle_track = content.Load<Texture2D>(PaddlesFolder + "paddle_track");

                    bullet = content.Load<Texture2D>(PaddlesFolder + "bullet");
                //
                #endregion
                //
                #region BALL
                //
                    bbball_black = content.Load<Texture2D>(BallsFolder + "bbball_black");
                    bbball_blue = content.Load<Texture2D>(BallsFolder + "bbball_blue");
                    bbball_blurple = content.Load<Texture2D>(BallsFolder + "bbball_blurple");
                    bbball_green = content.Load<Texture2D>(BallsFolder + "bbball_green");
                    bbball_greenblue = content.Load<Texture2D>(BallsFolder + "bbball_greenblue");
                    bbball_purple = content.Load<Texture2D>(BallsFolder + "bbball_Purple");
                    bbball_red = content.Load<Texture2D>(BallsFolder + "bbball_red");
                    bbball_yellow = content.Load<Texture2D>(BallsFolder + "bbball_yellow");

                    bbball_launchDirection = content.Load<Texture2D>(BallsFolder + "bbball_launchDirection");
                //
                #endregion
                //
                #region BRICK
                //
                    //brick_placeholder = content.Load<Texture2D>(BricksFolder + "brick_placeholder");
                    brick_red = content.Load<Texture2D>(BricksFolder + "brick_red");
                    brick_red_cracked = content.Load<Texture2D>(BricksFolder + "brick_red_cracked");
                    
                    brick_blue = content.Load<Texture2D>(BricksFolder + "brick_blue");
                    brick_blue_cracked = content.Load<Texture2D>(BricksFolder + "brick_blue_cracked");
                    brick_blue_cracked2 = content.Load<Texture2D>(BricksFolder + "brick_blue_cracked2");
            
                    brick_green = content.Load<Texture2D>(BricksFolder + "brick_green");
                    brick_green_cracked = content.Load<Texture2D>(BricksFolder + "brick_green_cracked");
                    brick_green_cracked2 = content.Load<Texture2D>(BricksFolder + "brick_green_cracked2");
                    brick_green_cracked3 = content.Load<Texture2D>(BricksFolder + "brick_green_cracked3");
                    
                    brick_orange = content.Load<Texture2D>(BricksFolder + "brick_orange");
                    brick_orange_cracked = content.Load<Texture2D>(BricksFolder + "brick_orange_cracked");
                    brick_orange_cracked2 = content.Load<Texture2D>(BricksFolder + "brick_orange_cracked2");
                    brick_orange_cracked3 = content.Load<Texture2D>(BricksFolder + "brick_orange_cracked3");
                    
                    brick_grey = content.Load<Texture2D>(BricksFolder + "brick_grey");
                //
                #endregion
                //
                #region POWER UP
                //
                    powerup_bomb = content.Load<Texture2D>(PowerupsFolder + "powerup_bomb");
                    powerup_doubleshooter = content.Load<Texture2D>(PowerupsFolder + "powerup_doubleshooter");
                    powerup_fast = content.Load<Texture2D>(PowerupsFolder + "powerup_fast");
                    powerup_long = content.Load<Texture2D>(PowerupsFolder + "powerup_long");
                    powerup_normal = content.Load<Texture2D>(PowerupsFolder + "powerup_normal");
                    powerup_shooter = content.Load<Texture2D>(PowerupsFolder + "powerup_shooter");
                    powerup_short = content.Load<Texture2D>(PowerupsFolder + "powerup_short");
                    powerup_slow = content.Load<Texture2D>(PowerupsFolder + "powerup_slow");
                    powerup_split = content.Load<Texture2D>(PowerupsFolder + "powerup_split");
                    powerup_sticky = content.Load<Texture2D>(PowerupsFolder + "powerup_sticky");
                    powerup_multiplierx2 = content.Load<Texture2D>(PowerupsFolder + "powerup_multiplierx2");
                    powerup_multiplierx4 = content.Load<Texture2D>(PowerupsFolder + "powerup_multiplierx4"); 
                //
                #endregion
            //
            #endregion Load Texture Assets

            #region Load Sound Effects
            //
                BrickHitSound = content.Load<SoundEffect>(AudioFolder + "gun7");
                BrickDestroyedSound = content.Load<SoundEffect>(AudioFolder + "explosion");
                PaddleCollisionSound = content.Load<SoundEffect>(AudioFolder + "boomshot");
                WallCollisionSound = content.Load<SoundEffect>(AudioFolder + "boomshot");
                //BackgroundMusic = content.Load<SoundEffect>(AudioFolder + "");
                DyingSound = content.Load<SoundEffect>(AudioFolder + "boo");
                BallLaunchSound = content.Load<SoundEffect>(AudioFolder + "lasergun2");
                ShootingSound1 = content.Load<SoundEffect>(AudioFolder + "m1shot");
                CollectPowerupSound = content.Load<SoundEffect>(AudioFolder + "powerup");
                LevelWonSound = content.Load<SoundEffect>(AudioFolder + "applause");
            //
            #endregion Load Sound Effects

            #region Load Fonts
            //
                font = content.Load<SpriteFont>(FontsFolder + "Font_Default");
                fontSelected = content.Load<SpriteFont>(FontsFolder + "Font_Selected");
            //
            #endregion
        //
            powerupManager = new BBPowerupManager();
            hud = new BBHud(3, 0);
        }

        // Not used unless we change all texture variables to private
        public static Texture2D getTexture(string textureName)
        {
        //
            #region BACKGROUND
            //
                if (textureName.StartsWith("background"))
                {
                    //if (textureName.EndsWith("yellow"))
                    //{
                    //    return background_yellow;
                    //}
                    //else

                    if (textureName.EndsWith("title"))
                    {
                        return background_title;
                    }
                    else if (textureName.EndsWith("menu"))
                    {
                        return background_menu;
                    }
                    else if (textureName.EndsWith("gamemode"))
                    {
                        return background_gamemode;
                    }
                    else if (textureName.EndsWith("help"))
                    {
                        return background_help;
                    }
                    else if (textureName.EndsWith("pause"))
                    {
                        return background_pause;
                    }
                    else if (textureName.EndsWith("ice01"))
                    {
                        return background_ice01;
                    }
                    else if (textureName.EndsWith("ice02"))
                    {
                        return background_ice02;
                    }
                    else if (textureName.EndsWith("grid"))
                    {
                        return background_grid;
                    }
                    else
                    {
                        return null;
                    }
                }
            //
            #endregion

            #region PADDLE
            //
                else if (textureName.StartsWith("paddle"))
                {
                    if (textureName.EndsWith("ball"))
                    {
                        return paddle_ball;
                    }
                    else if (textureName.EndsWith("short"))
                    {
                        return paddle_short;//short paddle texture
                    }
                    else if (textureName.EndsWith("normal"))
                    {
                        return paddle_normal; //normal paddle texture
                    }
                    else if (textureName.EndsWith("long"))
                    {
                        return paddle_long; //long paddle texture;
                    }
                    else
                    {
                        return null;
                    }
                }
            //
            #endregion

            #region BALL
            //
                else if (textureName.StartsWith("bbball"))
                {
                    if (textureName.EndsWith("black"))
                    {
                        return bbball_black;
                    }
                    else if (textureName.EndsWith("launchDirection"))
                    {
                        return bbball_launchDirection;
                    }
                    else if (textureName.EndsWith("greenblue"))
                    {
                        return bbball_greenblue;
                    }
                    else if (textureName.EndsWith("blue"))
                    {
                        return bbball_blue;
                    }
                    else if (textureName.EndsWith("green"))
                    {
                        return bbball_green;
                    }
                    else if (textureName.EndsWith("red"))
                    {
                        return bbball_red;
                    }
                    else if (textureName.EndsWith("yellow"))
                    {
                        return bbball_yellow;
                    }
                    else if (textureName.EndsWith("Purple"))
                    {
                        return bbball_purple;
                    }
                    else
                    {
                        return null;
                    }
                }
            //
            #endregion

            #region BRICK
            //
                else if (textureName.StartsWith("brick"))
                {
                    //if ( textureName.EndsWith("placeholder") ) { return brick_placeholder;
                    //}
                    //else 
                    if ( textureName.EndsWith("red") ) { return brick_red;
                    }
                    else if (textureName.EndsWith("red_cracked")) { return brick_red_cracked;
                    }
                    else if ( textureName.EndsWith("blue") ) { return brick_blue;
                    }
                    else if (textureName.EndsWith("blue_cracked")) { return brick_blue_cracked;
                    }
                    else if (textureName.EndsWith("blue_cracked2")) { return brick_blue_cracked2;
                    }
                    else if ( textureName.EndsWith("green")) { return brick_green;
                    }
                    else if (textureName.EndsWith("green_cracked")) { return brick_green_cracked;
                    }
                    else if (textureName.EndsWith("green_cracked2")) { return brick_green_cracked2;
                    }
                    else if (textureName.EndsWith("green_cracked3")) { return brick_green_cracked3;
                    }
                    else if ( textureName.EndsWith("orange") ) { return brick_orange;
                    }
                    else if (textureName.EndsWith("orange_cracked")) { return brick_orange_cracked;
                    }
                    else if (textureName.EndsWith("orange_cracked2")) { return brick_orange_cracked2;
                    }
                    else if (textureName.EndsWith("orange_cracked3")) { return brick_orange_cracked3;
                    }
                    else if ( textureName.EndsWith("grey") ) { return brick_grey;
                    }
                    
                    
                    
                    
                    else { return null;
                    }
                }
            //
            #endregion

            #region POWERUPS

                else if (textureName.StartsWith("powerup"))
                {
                    if (textureName.EndsWith("bomb"))
                    {
                        return powerup_bomb;
                    }
                    else if (textureName.EndsWith("doubleshooter"))
                    {
                        return powerup_doubleshooter;
                    }
                    else if (textureName.EndsWith("fast"))
                    {
                        return powerup_fast;
                    }
                    else if (textureName.EndsWith("long"))
                    {
                        return powerup_long; 
                    }
                    else if (textureName.EndsWith("normal"))
                    {
                        return powerup_normal;
                    }
                    else if (textureName.EndsWith("shooter"))
                    {
                        return powerup_shooter;
                    }
                    else if (textureName.EndsWith("short"))
                    {
                        return powerup_short;
                    }
                    else if (textureName.EndsWith("slow"))
                    {
                        return powerup_slow;
                    }
                    else if (textureName.EndsWith("split"))
                    {
                        return powerup_split;
                    }
                    else if (textureName.EndsWith("sticky"))
                    {
                        return powerup_sticky;
                    }
                    //else if (textureName.EndsWith("multiplierx2"))
                    //{
                    //    return powerup_multiplierx2;
                    //}
                    //else if (textureName.EndsWith("multiplierx4"))
                    //{
                    //    return powerup_multiplierx4;
                    //}
                    else
                    {
                        return null;
                    }
                }
                else
                {
                    return null;
                }

            #endregion
            //      
        }

        /// <summary>
        /// Sets the volume for the sound effects.
        /// </summary>
        /// <param name="volume">The percentage of volume. 0 (silence) to 1 (loudest).</param>
        public static void SetVolume(float volume)
        {
            // ensure the volume can't exceed 100%
            if (volume > 1.0f)
            {
                volume = 1.0f;
            }
            //
            SoundEffect.MasterVolume = volume;
        }
 }// end class
}// end namespace
